﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Progream15_GDI
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 绘画直线
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnLine_Click(object sender, EventArgs e)
        {
            //创建GDI对象
            Graphics g = this.CreateGraphics();
            //创建画笔对象
            Pen pen = new Pen(Color.Blue,4.0F);
            //短线点点
            //pen.DashStyle = DashStyle.Dot;
            float[] dashValues = { 5, 2, 15, 5 };
            pen.DashPattern = dashValues;

            //画直线，建立坐标
            Point p1 = new Point(30, 50);
            Point p2 = new Point(450, 50);
            //绘制直线
            g.DrawLine(pen, p1, p2);
        }

        private void btnRect_Click(object sender, EventArgs e)
        {
            //创建GDI对象
            Graphics g = this.CreateGraphics();
            //创建画笔对象
            Pen pen = new Pen(Color.Blue, 4.0F);

            //定义矩形大小
            Size size = new Size(100, 80);
            //坐标
            Point re = new Point(30, 60);
            //定义矩形
            Rectangle rect = new Rectangle(re,size);

            g.DrawRectangle(pen, rect);
        }

        private void btnCircle_Click(object sender, EventArgs e)
        {
            //创建GDI对象
            Graphics g = this.CreateGraphics();
            //创建画笔对象
            Pen pen = new Pen(Brushes.Gray, 8.0F);
            g.DrawEllipse(pen, 90, 90, 200, 200);
        }

        private void btnSector_Click(object sender, EventArgs e)
        {
            //创建GDI对象
            Graphics g = this.CreateGraphics();
            SolidBrush bush = new SolidBrush(Color.Crimson);

            g.FillPie(bush, 100, 100, 150, 150, 45,90);


            //创建画笔对象
            bush = new SolidBrush(Color.Aqua);
            g.FillPie(bush, 100, 100, 150, 150, 135, 90);

            //创建画笔对象
            bush = new SolidBrush(Color.Blue);
            g.FillPie(bush, 100, 100, 150, 150, 330, 90);

            //创建画笔对象
            bush = new SolidBrush(Color.White);
            g.FillPie(bush, 100, 100, 150, 150, 200, 90);

            //创建画笔对象
            bush = new SolidBrush(Color.Gray);
            g.FillPie(bush, 100, 100, 150, 150, 250, 90);

            //写字
            g.DrawString("年度业绩", new Font("微软雅黑", 14, FontStyle.Regular), Brushes.Black, new Point(40, 350));
        }
        private int i = 0;
        private void Form1_Load(object sender, EventArgs e)
        {
            i++;
            lblCount.Text = i.ToString();
        }

        private void label1_Click(object sender, EventArgs e)
        {
            label1.Text = ValidateCode.CreateVcode(4);
            //把图片读入内存
            MemoryStream ms = new MemoryStream();
            ms.Write(ValidateCode.CreateVCodePicture(label1.Text), 0, ValidateCode.CreateVCodePicture(label1.Text).Length);
            //显示图片的文件流格式
            pb_vCode.Image = Image.FromStream(ms);
        }
    }
}
